<textarea id="<?php echo $editor_name; ?>" class="editor" name="edit[<?php echo $editor_name; ?>]" style="width:100%"><?php echo $editor_value; ?></textarea>
<script type="text/javascript">
<?php if($isfull): ?>
tinymce.init({
	theme: "modern",
  	skin: 'light',
	selector: "#<?php echo $editor_name; ?>",
	plugins: [
		"advlist autolink autosave link image caption lists charmap print preview hr anchor pagebreak spellchecker",
		"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
		"table contextmenu directionality emoticons template textcolor paste fullpage textcolor colorpicker textpattern"
	],
	toolbar1: "addMedia",
	toolbar2: "newdocument fullpage | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
	toolbar3: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image caption media | forecolor backcolor | insertdatetime preview code",
	toolbar4: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",

	menubar: false,
	//toolbar_items_size: 'small',

	style_formats: [
		{title: 'Bold text', inline: 'b'},
		{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
		{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
		{title: 'Example 1', inline: 'span', classes: 'example1'},
		{title: 'Example 2', inline: 'span', classes: 'example2'},
		{title: 'Table styles'},
		{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
	],

	templates: [
		{title: 'Test template 1', content: 'Test 1'},
		{title: 'Test template 2', content: 'Test 2'}
	],

	image_advtab: true,
	//relative_urls: false,
	
	setup: function(editor) {
        editor.addButton('addMedia', {
            text: 'Add Media',
            icon: 'icon fa fa-camera', 
            onclick: function() {
                //editor.insertContent('Main button');
				$('#<?php echo $editor_name; ?>Modal').modal('toggle');
            }/*,
			onPostRender: function() {
				var ctrl = this;
				console.log(ctrl);
				editor.on('NodeChange', function(e) {
					//ctrl.active(e.element.nodeName == 'A');
				});
			}*/
        });
    }
});
<?php else : ?>
tinymce.init({
	theme: "modern",
  	skin: 'light',
	selector: "#<?php echo $editor_name; ?>",
	menubar: false,
  	plugins: [
		"advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
		"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
		"table contextmenu directionality emoticons template textcolor paste textcolor colorpicker textpattern responsivefilemanager caption"
	],
	toolbar1: "undo redo | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent",
   	toolbar2: "| responsivefilemanager | link unlink anchor | image media | forecolor backcolor | styleselect  | print preview code caption",
	image_advtab: true,
	remove_script_host : false,
	relative_urls: false,
	external_filemanager_path: "<?php echo base_url().'media/filemanager/'; ?>",
 	filemanager_title: "CMS Filemanager" ,
 	external_plugins: { "filemanager" : "<?php echo base_url().'media/filemanager/plugin.min.js'; ?>" },
	height: <?php echo $height ?>,
	//resize: "both",
	valid_elements: "@[class],p[style],h3,h4,h5,h6,a[href|target],strong/b,div[align],br,table,tbody,thead,tr,td,ul,ol,li,img[src]",
	setup: function(editor) {
        editor.addButton('addMedia', {
            text: 'Add Media',
            icon: 'icon fa fa-camera', 
            onclick: function() {
            	$('#<?php echo $editor_name; ?>Modal').modal('toggle');
            }
        });
    }
});
<?php endif; ?>
$(document).ready(function() {
	$('#<?php echo $editor_name; ?>Modal').on('show.bs.modal', function (event) {
		$(this).find('.modal-dialog').css({
			'margin-top': '70px'
		});
	});
});
</script>

<div class="modal fade modal-media" tabindex="-1" role="dialog" aria-labelledby="<?php echo $editor_name; ?>ModalLabel" aria-hidden="true" id="<?php echo $editor_name; ?>Modal">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title">Insert Media</h4>
			</div>
			<div class="modal-body">
				<p>One fine body&hellip;</p>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				<button type="button" class="btn btn-primary">Insert into post</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->